package com.spddr.pmos.cxf.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.spddr.pmos.cxf.JaxrsObjectType;
import com.spddr.pmos.domain.TreeLevel;
import com.spddr.pmos.jpa.Metric;
import com.spddr.pmos.jpa.ObjectType;
import com.spddr.pmos.repos.ObjectMetricRepos;
import com.spddr.pmos.repos.ObjectTypeRepos;

@Service
public class JaxrsObjectTypeImpl extends AbstractJaxrsTypeImpl<ObjectType> implements JaxrsObjectType {
	@Autowired
	private ObjectTypeRepos repository;
	@Autowired
	private ObjectMetricRepos omRepos;

	@Override
	public JpaRepository<ObjectType, Integer> getRepository() {
		return repository;
	}

	@Override
	public List<Metric> findMetrics(String clz) {
		return omRepos.findByIdObjectType(TreeLevel.valueOf(clz).id)
				.stream()
				.map(x -> x.getMetric())
				.collect(Collectors.toList());
	}
}
